/*
 * SocketSSL.h
 *
 *  Created on: 12.12.2011
 *      Author: Pavel Sinay
 */

#ifndef SOCKETSSL_H_
#define SOCKETSSL_H_

#include <openssl/ssl.h>

#include "SocketTCP.h"

class SocketSSL: public SocketTCP {
public:
	SocketSSL();
	virtual ~SocketSSL();

	/*virtual*/ int connectServer(std::string ip, size_t port);
	/*virtual*/ int disconnect();
	/*virtual*/ int sendMessage(std::vector<char> const& msg);
	/*virtual*/ int receiveMessage(std::vector<char> & msg);
private:
	SSL_CTX *m_ctx;
	SSL *m_ssl;
	BIO *m_sbio;
	BIO *m_bio_err;

	int receiveBlock(char* msg, size_t size);
	int connectTCP(std::string ip, size_t port);
	void printSSLError(std::string string);
	SSL_CTX *initializeCTX();
};

#endif /* SOCKETSSL_H_ */
